package com.lykj.modules.shop.mapper;

import com.lykj.modules.shop.entity.UserBill;
import com.lykj.modules.shop.excel.UserBillExcel;
import com.lykj.modules.shop.vo.UserBillVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * 用户账单表 Mapper 接口
 *
 * @author cxl
 * @since 2022-01-14
 */
public interface UserBillMapper extends BaseMapper<UserBill> {

	/**
	 * 自定义分页
	 *
	 * @param page
	 * @param userBill
	 * @return
	 */
	List<UserBillVO> selectUserBillPage(IPage page, UserBillVO userBill);

	@Select("<script>select b.*, u.account, u.uid from shsy_user_bill b LEFT JOIN lykj_user u on u.id=b.user_id where b.is_deleted = 0" +
		"<if test=\"userBill.id!=null\">" +
		" and b.id = #{userBill.id}" +
		"</if>" +
		"<if test=\"userBill.tenantId!=null and userBill.tenantId!=''\">" +
		" and b.tenant_id = #{userBill.tenantId}" +
		"</if>" +
		"<if test=\"userBill.userId!=null\">" +
		" and b.user_id = #{userBill.userId}" +
		"</if>" +
		"<if test=\"userBill.category!=null and userBill.category!=''\">" +
		" and b.category = #{userBill.category}" +
		"</if>" +
		"<if test=\"userBill.type!=null\">" +
		" and b.type = #{userBill.type}" +
		"</if>" +
		"<if test=\"userBill.linkId!=null\">" +
		" and b.link_id = #{userBill.linkId}" +
		"</if>" +
		"<if test=\"userBill.account!=null and userBill.account!=''\">" +
		" and u.account = #{userBill.account}" +
		"</if>" +
		"<if test=\"userBill.uid!=null\">" +
		" and u.uid = #{userBill.uid}" +
		"</if>" +
		"<if test=\"userBill.status!=null\">" +
		" and b.status = #{userBill.status}" +
		"</if>" +
		"<if test=\"userBill.startDate!=null and userBill.endDate!=null\">" +
		" and b.create_time BETWEEN CONCAT(#{userBill.startDate},' 00:00:00') AND CONCAT(#{userBill.endDate},' 23:59:59')" +
		"</if>" +
		"</script>")
	List<UserBillExcel> export(@Param("userBill") UserBillVO userBill);
}
